package com.easylinkin.linkappapi.gaodemap.controller;

import com.easylinkin.linkappapi.gaodemap.entity.InverseCodingParams;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import site.morn.rest.RestBuilders;
import site.morn.rest.RestMessage;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutionException;

/**
 * class info :
 *
 * @author liuqihang
 * @date 2021/6/24 17:08
 */
@RestController
@RequestMapping("/map")
@Slf4j
public class MapApiController {

    @Resource
    private com.easylinkin.linkappapi.gaodemap.service.GaoDeApiService gaoDeApiService;

    @PostMapping("getAddressList")
    public RestMessage getAddressList(@RequestBody List<InverseCodingParams> parameters) throws ExecutionException, InterruptedException {
        Assert.notNull(parameters, "查询参数不能为空");
        Map<String, String> geographyInverseCoding = gaoDeApiService.getGeographyInverseCoding(parameters);
        if(geographyInverseCoding != null && geographyInverseCoding.size() ==0){
            for(InverseCodingParams inverseCodingParams : parameters){
                geographyInverseCoding.put(inverseCodingParams.getLocation(),"无法获取");
            }
        }
        return RestBuilders.successBuilder().data(geographyInverseCoding).build();
    }

    @PostMapping("convertLocationTest")
    public RestMessage convertLocationTest() throws ExecutionException, InterruptedException {
        gaoDeApiService.convertLocationTest();
        return RestBuilders.successBuilder().build();
    }
}
